package com.ruoyi.common.utils;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;

/**
 * @Description : 短信工具类
 * @Author : MP
 * @CreateDate : 2020/2/12 11:55
 * @UpdateUser : MP
 * @UpdateDate : 2020/2/12 11:55
 * @UpdateRemark : 修改内容
 * @Version : 1.0
 */
public class SmsUtil
{
    
    private static DefaultProfile getSmsProfile()
    {
        return DefaultProfile.getProfile("cn-hangzhou", "LTAI4G7YaiXTECS5T6hj6Xfg", "oH2xeQ2K8jqbTaRX4FG24Pb5gNV2Xm");
    }
    
    /**
     * 
     * <一句话功能简述> <功能详细描述>
     * 
     * @param msg 验证码
     * @param phone 接受手机号码
     * @param templateCode 模板 从枚举里面获取
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static JSONObject sendSms(int verCode, String phone, String templateCode)
    {
        
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("code", verCode);
        
        IAcsClient iAcsClient = new DefaultAcsClient(getSmsProfile());
        CommonRequest request = new CommonRequest();
        request.setMethod(MethodType.POST);
        request.setDomain("dysmsapi.aliyuncs.com");
        request.setVersion("2017-05-25");
        request.setAction("SendSms");
        request.putQueryParameter("RegionId", "cn-hangzhou");
        request.putQueryParameter("PhoneNumbers", phone);
        request.putQueryParameter("SignName", "智享久链");
        request.putQueryParameter("TemplateCode", templateCode);
        request.putQueryParameter("TemplateParam", JSON.toJSONString(param));
        try
        {
            CommonResponse response = iAcsClient.getCommonResponse(request);
            return JSON.parseObject(response.getData());
        }
        catch (ClientException e)
        {
            e.printStackTrace();
        }
        return null;
    }
    
    public static void main(String[] args)
    {
        
    }

    /**
     * 验证码生成
     * <一句话功能简述>
     * <功能详细描述>
     * @return
     * @see [类、类#方法、类#成员]
     */
    public static int createRandomNum5()
    {
        return (int)((Math.random() * 9 + 1) * 10000);
    }
    
}
